using System;
using Autofac;
using Cysharp.Threading.Tasks;
using JetBrains.Annotations;
using uMVP;
using uMVP.AutofacExtends;
using UnityEngine;

namespace Samples
{
    public class Main : MonoBehaviour
    {
        public void Start()
        {
            var builder = new ContainerBuilder();
            builder.RegisterMvp<IViewA, ViewA, IPresenterA, PresenterA>();
            var container = builder.Build();
            var view = container.Resolve<IViewA>();
            view.Destroy();
        }
    }

    public interface IViewA : IView
    {
    }

    [PrefabPath("UI/ViewA", "/Canvas")]
    public class ViewA : ViewBase<IPresenterA>, IViewA
    {
        ~ViewA()
        {
            Debug.Log("~ViewA");
        }
        public override UniTask OnInitializeAsync()
        {
            return UniTask.CompletedTask;
        }

        public override void OnDestroy()
        {
        }
    }

    public interface IPresenterA : IPresenter
    {
    }

    public class PresenterA : PresenterBase<IViewA>, IPresenterA
    {
        ~PresenterA()
        {
            Debug.Log("~PresenterA");
        }
        public PresenterA([NotNull] IViewA view) : base(view)
        {
        }
    }
}